import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import createRouteGuard from './guard'

const routes: RouteRecordRaw[] = [
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue')
    },
    {
        path: '/privacy',
        name: 'privacy',
        component: () => import('@/views/login/privacy.vue')
    },
    {
        path: '/',
        name: 'layout',
        component: () => import('@/layout/main-layout.vue'),
        children: [
            {
                path: '/generator',
                name: 'generator',
                component: () => import('@/views/generator/index.vue'),
                meta: {
                    title: '代码生成'
                }
            },
            {
                path: '/demo',
                name: 'demo',
                meta: {
                    title: '示例页面'
                },
                redirect: '/demo/table-list',
                children: [
                    {
                        path: '/demo/table-list',
                        name: 'table-list',
                        component: () => import('@/views/demo/table-list/index.vue'),
                        meta: {
                            title: '表格页'
                        }
                    },
                    {
                        path: '/demo/form-page',
                        name: 'form-page',
                        component: () => import('@/views/demo/form-page/index.vue'),
                        meta: {
                            title: '表单页'
                        }
                    }
                ]
            }
        ]
    },
    {
        path: '/:pathMatch(.*)',
        name: '404',
        component: () => import('@/views/exception/404.vue')
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

createRouteGuard(router)

export default router
